#!/bin/bash

./modes.pl "revisedGrailPsalter/Psalm\ 1" three a b | sed -f sedaccents > Psalm001.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 2" two a_prime b | sed -f sedaccents > Psalm002.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 3" one a b | sed -f sedaccents > Psalm003.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 4" six a b | sed -f sedaccents > Psalm004.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 5" one a_prime b_prime | sed -f sedaccents > Psalm005.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 6" four a b | sed -f sedaccents > Psalm006.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 7" three a b | sed -f sedaccents > Psalm007.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 8" seven a b | sed -f sedaccents | sed -f sedaccents > Psalm008.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 9" seven b_prime a | sed -f sedaccents > Psalm009A.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 10" seven a b_prime | sed -f sedaccents > Psalm009B.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 11" eight a_dprime b | sed -f sedaccents > Psalm010.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 12" peregrinus a b | sed -f sedaccents > Psalm011.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 13" seven a b_prime | sed -f sedaccents > Psalm012.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 14" two b a | sed -f sedaccents > Psalm013.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 15" eight a_dprime b | sed -f sedaccents > Psalm014.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 16" four b_prime a_prime | sed -f sedaccents > Psalm015.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 17" five a_prime b | sed -f sedaccents > Psalm016.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 18" two a_prime b | sed -f sedaccents > Psalm017.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 19" eight a_dprime b | sed -f sedaccents > Psalm018.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 20" three b a | sed -f sedaccents > Psalm019.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 21" four b_prime a_prime | sed -f sedaccents > Psalm020.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 22" one a_prime b_prime | sed -f sedaccents > Psalm021.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 23" four a b | sed -f sedaccents > Psalm022.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 24" peregrinus a b | sed -f sedaccents > Psalm023.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 25" six b a_prime | sed -f sedaccents > Psalm024.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 26" five a_prime b | sed -f sedaccents > Psalm025.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 27" eight a_dprime b | sed -f sedaccents > Psalm026.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 28" two a_prime b | sed -f sedaccents > Psalm027.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 29" eight a_dprime b | sed -f sedaccents > Psalm028.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 30" six a b | sed -f sedaccents > Psalm029.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 31" six a b | sed -f sedaccents > Psalm030.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 32" one b_dprime a_prime | sed -f sedaccents > Psalm031.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 33" five a_prime b | sed -f sedaccents > Psalm032.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 34" five a_prime b | sed -f sedaccents > Psalm033.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 35" one a b | sed -f sedaccents > Psalm034.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 36" six b a | sed -f sedaccents > Psalm035.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 37" two a_prime b | sed -f sedaccents > Psalm036.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 38" two a_prime b | sed -f sedaccents > Psalm037.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 39" seven b a | sed -f sedaccents > Psalm038.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 40" four a_prime b_prime | sed -f sedaccents > Psalm039.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 41" six b a_prime | sed -f sedaccents > Psalm040.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 42" one a b | sed -f sedaccents > Psalm041.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 43" three a b | sed -f sedaccents > Psalm042.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 44" peregrinus a b | sed -f sedaccents > Psalm043.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 45" eight a_prime b | sed -f sedaccents > Psalm044.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 46" five a_prime b | sed -f sedaccents > Psalm045.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 47" two a_prime b | sed -f sedaccents > Psalm046.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 48" five a_prime b | sed -f sedaccents > Psalm047.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 49" four a_prime b_prime | sed -f sedaccents > Psalm048.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 50" one a_prime b_prime | sed -f sedaccents > Psalm049.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 51" eight a_dprime b | sed -f sedaccents > Psalm050.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 52" one a_prime b_prime | sed -f sedaccents > Psalm051.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 53" two b a | sed -f sedaccents > Psalm052.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 54" six a b | sed -f sedaccents > Psalm053.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 55" three b a | sed -f sedaccents > Psalm054.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 56" six a b | sed -f sedaccents > Psalm055.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 57" four b a | sed -f sedaccents > Psalm056.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 58" three a b | sed -f sedaccents > Psalm057.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 59" one b a | sed -f sedaccents > Psalm058.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 60" two a_prime b | sed -f sedaccents > Psalm059.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 61" eight a b | sed -f sedaccents > Psalm060.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 62" one a b | sed -f sedaccents > Psalm061.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 63" one b a | sed -f sedaccents > Psalm062.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 64" three b a | sed -f sedaccents > Psalm063.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 65" two a_prime b | sed -f sedaccents > Psalm064.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 66" five a_prime b | sed -f sedaccents > Psalm065.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 67" two a_prime b | sed -f sedaccents > Psalm066.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 68" seven b_prime a | sed -f sedaccents > Psalm067.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 69" one a b | sed -f sedaccents > Psalm068.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 70" six b a_prime | sed -f sedaccents > Psalm069.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 71" seven a b | sed -f sedaccents > Psalm070.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 72" one a_prime b_prime | sed -f sedaccents > Psalm071.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 73" eight a b | sed -f sedaccents > Psalm072.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 74" four a b | sed -f sedaccents > Psalm073.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 75" five a_prime b | sed -f sedaccents > Psalm074.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 76" three a b | sed -f sedaccents > Psalm075.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 77" one a b | sed -f sedaccents > Psalm076.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 7800" one a b | sed -f sedaccents > Psalm077A.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 7801" six b a_prime | sed -f sedaccents > Psalm077B.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 79" two a b | sed -f sedaccents > Psalm078.tex;
./modes.pl "revisedGrailPsalter/Psalm\ 80" three a b | sed -f sedaccents > Psalm079.tex;

echo "\documentclass[12pt,twoside,a5paper]{memoir}" > newPsalter.tex;
echo "\usepackage{verse}" >> newPsalter.tex;
echo "\usepackage{../psaltertitle}" >> newPsalter.tex;
echo "\usepackage{xunicode}" >> newPsalter.tex;
echo "\usepackage{fontspec}" >> newPsalter.tex;
echo "\usepackage{xltxtra}" >> newPsalter.tex;
echo "\setmainfont[Mapping=tex-text,Numbers=OldStyle]{Adobe Jenson Pro}" >> newPsalter.tex;
echo "\usepackage{../psalter}"  >> newPsalter.tex;
echo "\semiisopage[8]" >> newPsalter.tex;
#echo "\setstocksize{210mm}{148mm}" >> newPsalter.tex;
#echo "\settrimmedsize{195mm}{125mm}{*}" >> newPsalter.tex;
#echo "\setlength{\trimtop}{0pt}" >> newPsalter.tex;
#echo "\setlength{\trimedge}{\stockwidth}" >> newPsalter.tex;
#echo "\addtolength{\trimedge}{-\paperwidth}" >> newPsalter.tex;
#echo "\settrims{5mm}{0mm}" >> newPsalter.tex;
#echo "\settypeblocksize{180mm}{120mm}{*}" >> newPsalter.tex;
#echo "\setlrmarginsandblock{.4cm}{*}{*}" >> newPsalter.tex;
#echo "\setulmarginsandblock{.9cm}{*}{*}" >> newPsalter.tex;
#echo "\setlrmargins{*}{*}{1.8}" >> newPsalter.tex;
#echo "\setheadfoot{\onelineskip}{\onelineskip}" >> newPsalter.tex;
#echo "\setheaderspaces{*}{\onelineskip}{*}" >> newPsalter.tex;
echo "\checkandfixthelayout" >> newPsalter.tex;
echo "\nouppercaseheads" >> newPsalter.tex;
echo "\begin{document}" >> newPsalter.tex;
echo "\pagestyle{empty}" >> newPsalter.tex;
echo "\titleWH" >> newPsalter.tex;
echo "\clearpage" >> newPsalter.tex;
echo "\setcounter{page}{1}" >> newPsalter.tex;
echo "\makepagestyle{psalter}" >> newPsalter.tex;
echo "\makeoddhead{psalter}{\textcolor{red}{\leftmark}}{}{}" >> newPsalter.tex;
echo "\makeevenhead{psalter}{}{}{\textcolor{red}{\rightmark}}" >> newPsalter.tex;
echo "\makeoddfoot{psalter}{\textcolor{red}{\thepage}}{}{}" >> newPsalter.tex;
echo "\makeevenfoot{psalter}{}{}{\textcolor{red}{\thepage}}" >> newPsalter.tex;
#echo "\makepsmarks{psalter}{" >> newPsalter.tex;
#echo "\createmark{poemtitle}{both}{nonumber}{}{}}" >> newPsalter.tex;
echo "\PlainPoemTitle" >> newPsalter.tex;
echo "\pagestyle{psalter}" >> newPsalter.tex;
echo "\renewcommand*{\poemtitlemark}[1]{\markboth{#1}{#1}}" >> newPsalter.tex;
echo "\renewcommand*{\PoemTitlefont}{\centering\scshape\large}" >> newPsalter.tex;
for i in `ls Psalm*|grep Psalm*[0-9]`; do export psalm=$(echo $i|sed 's/Psalm0*\([1-9][0-9]*[AB]*\)\.tex/\1/g;'); echo "\needspace{3\baselineskip}" >> newPsalter.tex; echo "\PoemTitle[ps. $psalm]{\textline[t]{\hfill}{$(head ../en-US/p$psalm.ly |awk -F"\"" '{if ($1 ~/markup/){printf $2}}')}{$(head ../en-US/p$psalm.ly |awk -F"\"" '{if ($1 ~ /markup/){printf $4}}')}}" >> newPsalter.tex; echo "\input{`basename $i .tex`}" >> newPsalter.tex; done

echo "\end{document}" >> newPsalter.tex;
#echo "\documentclass[10pt,letterpaper,twoside]{report}" > newPsalter1-49.tex;
#echo "\usepackage{verse}" >> newPsalter1-49.tex;
#echo "\usepackage{psalter}" >> newPsalter1-49.tex;
#echo "\begin{document}" >> newPsalter1-49.tex;
#for i in `seq 1 49`; do echo "\input{Psalm$i}" >> newPsalter1-49.tex; done
#echo "\end{document}" >> newPsalter1-49.tex;
#echo "\documentclass[10pt,letterpaper,twoside]{report}" > newPsalter50-99.tex;
#echo "\usepackage{verse}" >> newPsalter50-99.tex;
#echo "\usepackage{psalter}" >> newPsalter50-99.tex;
#echo "\begin{document}" >> newPsalter50-99.tex;
#for i in `seq 50 54`; do echo "\input{Psalm$i}" >> newPsalter50-99.tex; done
#echo "\end{document}" >> newPsalter50-99.tex;
sed -i 's/p9.ly/p9A.ly/' Psalm009A.tex;
sed -i 's/p9.ly/p9B.ly/' Psalm009B.tex;
sed -i 's/p77.ly/p77A.ly/' Psalm077A.tex;
sed -i 's/p77.ly/p77B.ly/' Psalm077B.tex;
